package hn.sigit.model.ladm.party;

import java.io.Serializable;
import javax.persistence.*;
@Entity
@org.hibernate.annotations.Proxy(lazy=false)
@Table(name="LA_GroupParty", schema="ladm_party")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorValue("LA_GroupParty")
@PrimaryKeyJoinColumn(name="LA_PartyID", referencedColumnName="ID")

public class LA_GroupParty extends LA_Party implements Serializable {
	private static final long serialVersionUID = 1L;
	private LA_GroupPartyType groupPartyType;
	private java.util.Set<LA_PartyMember> la_partymembers = new java.util.HashSet<LA_PartyMember>();
	
	public LA_GroupParty() {
	}
	
	@Column(name="GroupPartyType", nullable=true)
	@Enumerated(EnumType.STRING)
	public LA_GroupPartyType getGroupPartyType() {
		return groupPartyType;
	}
	public void setGroupPartyType(LA_GroupPartyType value) {
		this.groupPartyType = value;
	}
	
	@OneToMany(mappedBy="la_groupparty", targetEntity=LA_PartyMember.class)	
	@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.LOCK})	
	@org.hibernate.annotations.LazyCollection(org.hibernate.annotations.LazyCollectionOption.TRUE)	
	public java.util.Set<LA_PartyMember> getLa_partymembers() {
		return la_partymembers;
	}
	public void setLa_partymembers(java.util.Set<LA_PartyMember> value) {
		this.la_partymembers = value;
	}
	
	@Transient
	public LA_Party[] getLa_partys() {
		java.util.ArrayList lValues = new java.util.ArrayList(5);
		for(java.util.Iterator lIter = la_partymembers.iterator();lIter.hasNext();) {
			lValues.add(((LA_PartyMember)lIter.next()).getLa_party());
		}
		return (LA_Party[])lValues.toArray(new LA_Party[lValues.size()]);
	}
	
	public void removeLa_party(LA_Party aLa_party) {
		LA_PartyMember[] lLa_partymembers = (LA_PartyMember[])la_partymembers.toArray(new LA_PartyMember[la_partymembers.size()]);
		for(int i = 0; i < lLa_partymembers.length; i++) {
			if(lLa_partymembers[i].getLa_party().equals(aLa_party)) {
				la_partymembers.remove(lLa_partymembers[i]);
			}
		}
	}
	
	public void addLa_party(LA_PartyMember aLA_PartyMember, LA_Party aLa_party) {
		aLA_PartyMember.setLa_party(aLa_party);
		la_partymembers.add(aLA_PartyMember);
	}
	
	public LA_PartyMember getLa_partymemberByLa_party(LA_Party aLa_party) {
		LA_PartyMember[] lLa_partymembers = (LA_PartyMember[])la_partymembers.toArray(new LA_PartyMember[la_partymembers.size()]);
		for(int i = 0; i < lLa_partymembers.length; i++) {
			if(lLa_partymembers[i].getLa_party().equals(aLa_party)) {
				return lLa_partymembers[i];
			}
		}
		return null;
	}
	
	public String toString() {
		return super.toString();
	}
	
}
